package com.gzist.elderlyserviceplatform.service;

import com.gzist.elderlyserviceplatform.entity.dto.ElderlyHealthAnalysisDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 健康报告处理类
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class HealthReportFacade {

    private final AiService aiService;
    private final PdfConverterService pdfService;
    private final HealthReportEmailService emailService;

    @Transactional
    public void processAndSendReport(ElderlyHealthAnalysisDTO dto) {
        // 步骤1：生成AI报告
        String markdown = aiService.generateHealthPlan(dto);
        // 步骤2：转换为PDF并上传
        String reportUrl = pdfService.convertToPdfAndUpload(markdown);
        // 步骤3：发送邮件
        emailService.sendHealthReport(dto.getRecipientEmail(), dto.getElderlyName(), reportUrl);

    }
}
